# include <iostream>
# include <algorithm>
# include <cstdio>
const int maxn = 1005;
int s;
int a[maxn][maxn];
int f[maxn][maxn];
const int dx[] = {0,0,-1,1};
const int dy[] = {-1,1,0,0};
int dp(int i, int j)
{
    if (f[i][j] >= 0) return f[i][j];
    f[i][j] = 0;
    for (int x = 0; x < 4; ++x) {
        int ni = i + dx[x];
        int nj = j + dy[x];
        if (1<=ni&&ni<=s &&1<=nj&&nj<=s && a[ni][nj]==a[i][j]+1) {
            f[i][j] = std::max(f[i][j], dp(ni,nj)+1);
        }
    }
    return f[i][j];
}
int main()
{
    freopen("A-small-attempt0 (1).in", "r", stdin);
    freopen("a-small-out.txt", "w", stdout);
    int T;
    std::cin >> T;
    for (int ica = 1; ica <= T; ++ica) {
        std::cin >> s;
        for (int i = 1; i <= s; ++i) {
            for (int j = 1; j <= s; ++j) {
                std::cin >> a[i][j];
                f[i][j] = -1;
            }
        }
        int ax, ay = 0;
        for (int i = 1; i <= s; ++i) {
            for (int j = 1; j <= s; ++j) {
                if (dp(i,j) > ay) {
                    ay = dp(i,j);
                    ax = a[i][j];
                } else if (dp(i,j) == ay) {
                    ax = std::min(ax, a[i][j]);
                }
            }
        }
        std::cout << "Case #" << ica << ": " << ax << " " << ay+1 << std::endl;
    }
    return 0;
}
